package com.xhsj.user.hr.system.service;

import com.xhsj.user.hr.base.BaseParam;
import com.xhsj.user.config.UploadPathConfig;
import com.xhsj.user.hr.system.entity.TbHrZhaopinEmploy;
import com.xhsj.user.hr.system.mapper.TbHrZhaopinEmployMapper;
import com.xhsj.user.hr.system.service.TbHrZhaopinEmployService;
import com.xhsj.user.hr.base.BaseService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Collection;
import java.util.Map;
import java.util.Objects;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.io.Serializable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import lombok.extern.slf4j.Slf4j;
/**
 * <p>
 * 录用记录表 服务实现类
 * </p>
 *
 * @author suxiaolin
 * @since Sep 7, 2020 4:12:00 PM
 */
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
//@CacheConfig(cacheNames = "TbHrZhaopinEmploy")
public class TbHrZhaopinEmployService extends BaseService<TbHrZhaopinEmployMapper, TbHrZhaopinEmploy>{
    @Autowired
    private TbHrZhaopinEmployMapper dao;


    @Autowired
    private UploadPathConfig uploadPath;

	/**
	 * 保存
	 * @author suxiaolin
	 * @date Sep 7, 2020 4:12:00 PM
	 */
    @Override
    //@CacheEvict(cacheNames="TbHrZhaopinEmploy", allEntries=true)
    public boolean save(TbHrZhaopinEmploy entity) {
        return super.save(entity);
    }

	/**
	 * 通过id获取数据
	 * @author suxiaolin
	 * @date Sep 7, 2020 4:12:00 PM
	 */
    @Override
    //@Cacheable(key = "#id",sync = true)
    public TbHrZhaopinEmploy getById(Serializable id) {
        return super.getById(id);
    }

	/**
	 * 通过id删除数据
	 * @author suxiaolin
	 * @date Sep 7, 2020 4:12:00 PM
	 */
    @Override
    //@CacheEvict(cacheNames="TbHrZhaopinEmploy", allEntries=true)
    public boolean removeById(Serializable id) {
        return super.removeById(id);
    }

	/**
	 * 批量删除数据
	 * @author suxiaolin
	 * @date Sep 7, 2020 4:12:00 PM
	 */
    //@CacheEvict(cacheNames="SysDict", allEntries=true)
    @Override
    public boolean removeByIds(Collection<? extends Serializable> idList) {
        return super.removeByIds(idList);
    }

	/**
	 * 分页查询数据
	 * @author suxiaolin
	 * @date Sep 7, 2020 4:12:00 PM
	 */
    //@Cacheable(key = "#data",sync = true)
    public IPage<TbHrZhaopinEmploy> selectPage(BaseParam data) {

        Page<TbHrZhaopinEmploy> page = new Page(data.getPage(),data.getSize());
        return dao.findList(page,data);
    }

	/**
	 * 查询所有数据
	 * @author suxiaolin
	 * @date Sep 7, 2020 4:12:00 PM
	 */
    @Override
    //@Cacheable(value = "TbHrZhaopinEmploy",sync = true)
    public List<TbHrZhaopinEmploy> selectAll() {
        return super.selectAll();
    }


    /**
     * 物理删除数据库记录
     * @author 苏小林
     * @date 2020/9/8 9:26
     * @param: id
     */
    public void delById(Long id,String path) throws Exception {
        dao.delById(id);
        path = uploadPath.getPath() + "/" + path.substring(path.lastIndexOf("download/") + 9);

        Path filePath = Paths.get(path);
        File toFile = filePath.toFile();
        boolean exists = toFile.exists();
        if (exists) {
            Files.delete(filePath);
        } else {
            throw new Exception("找不到文件路径");
        }
    }
}
